package com.cn.io.socket;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;

public class DatagramClient {

    public static void main(String[] args) throws IOException, InterruptedException {
        DatagramChannel sendChannel = DatagramChannel.open();
        InetSocketAddress socketAddress =
                new InetSocketAddress("127.0.0.1", 25000);
        while (true) {
            ByteBuffer buffer = ByteBuffer.wrap("发送 DataGram 测试数据".getBytes(StandardCharsets.UTF_8));
            sendChannel.send(buffer, socketAddress);
            System.out.println("send success!");
            TimeUnit.SECONDS.sleep(10);
        }
    }

}
